package org.usmile.algorithms.huawei.acm;

import java.util.Scanner;

// https://fcqian.blog.csdn.net/article/details/128378675
public class _查找重复代码 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String str1 = sc.next();
        String str2 = sc.next();

        System.out.println(getResult(str1, str2));
    }

    public static String getResult(String str1, String str2) {
        int n = str1.length();
        int m = str2.length();

        int[][] dp = new int[n + 1][m + 1];

        int max = 0;
        String ans = "";

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (str1.charAt(i - 1) == str2.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;

                    if (dp[i][j] > max) {
                        max = dp[i][j];
                        ans = str1.substring(i - max, i);
                    }
                } else {
                    dp[i][j] = 0;
                }
            }
        }

        return ans;
    }
}
